package com.itheima.controller;

import com.itheima.bean.Student;
import com.itheima.service.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    StudentServiceImpl service = new StudentServiceImpl();

    @Test
    public void finAll() {
        ArrayList<Student> list = service.findAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    @Test
    public void findById() {
        Student stu = service.findById(3);
        System.out.println(stu);
    }

    @Test
    public void insert() {
        Student stu = new Student(5, "可乐", 33, new Date());
        int res = service.insert(stu);
        if (res != 0) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }

    @Test
    public void delete() {
        int res = service.delete(9);
        if (res != 0) {
            System.out.println("删除成功");
        } else {
            System.out.println("删除失败");
        }
    }

    @Test
    public void update() {
        Student stu = new Student(5, "开口", 33, new Date());
        int res = service.update(stu, 9);
        if (res != 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }
}
